build_dyn_new <- function(con, data_name  = "test_dt_withProb_cancer"){
  
  monthly_data<- get_revision_cancer_monthly_data(con= con) %>%
    add_grouped_cancer_type() %>% 
    select(id_var,S_index_date_XX,DMG_died_within_365d,
           DMG_date_of_death_XX,CNRS_topo_main_groups,S_sample_source_XX ) %>% 
    collect() %>% 
    mutate(month_from_index = gsub("[^0-9\\.]", "", S_sample_source_XX)) %>% 
    mutate(month_from_index = if_else(month_from_index =="",1,as.numeric(month_from_index))-1 ) %>% 
    data.table() 
  
  monthly_data[month_from_index==0 ,
               died_first_year1 := DMG_died_within_365d ]
  
  monthly_data[,died_first_year:=mean(as.integer(as.character(died_first_year1)),na.rm = T),
               by=.(id_var) ][, died_first_year1 := NULL]
  
  monthly_data[,month_lived:=max(month_from_index)+1,
               by=.(id_var) ]
  
  monthly_data[died_first_year==1,
               full_month_to_death := month_lived-month_from_index-1]
  

  monthly_result <- get(load("revision_monthly.RData"))

  monthly_result <- 
    monthly_result %>%  map(~chuck(., 'preds_test')  ) %>% 
    bind_rows(,.id = "month") %>% 
    mutate(month_from_index = gsub("[^0-9\\.]", "", month)) %>% 
    mutate(month_from_index = if_else(month_from_index =="",1,as.numeric(month_from_index))-1 ) %>% 
    select("preds_after_bayes", "month_from_index"  , "id_var" ) %>%
    inner_join(monthly_data ,
               by = c("id_var" = "id_var",
                      "month_from_index" = "month_from_index")) %>% 
    mutate(prob_for_report = preds_after_bayes) %>%
    select(-preds_after_bayes) %>% 
    data.table()
  
  return(monthly_result)
  
}

